function page1() {
    var text = ""; 
    text += "A <b>killer</b> is on the loose!";

    text += "<p>You are a detective from the local police office and you must catch ";
    text += "the killer as soon as you can to prevent him from killing again.</p>";
    
    text += "<p>In order to figure out <i>who</i> the killer is, you first need to figure out <i>why</i> he ";
    text += "kills the people he does.</p>";

    text += "<p>You travel to the spot of the killings...</p>";

    $("div#storyText").html(text);
    $("span#pageNum").html("1");
}

function page2() {
    var text = ""; 
    text += "Using your top-secret local police precinct technologies, you're able to locate and map the "; 
    text += "positions of everyone nearby.";

    text += "<br/><br/><img src=\"images/map.png\" height=\"150px\" />";

    text += "<p>These people must know something about the people who have died. ";
    text += "Walk close to them and press the \"Start Conversation\" button to see what they know!</p>";

    $("div#storyText").html(text);
    $("span#pageNum").html("2");
}

function page3() {
    var text = ""; 
    text += "Talking with the locals lets you learn characteristics of them and the victims. The "; 
    text += "killer must be killing people who like the things that he dislikes. Find out what each "; 
    text += "player likes and dislikes to identify the killer.";

    text += "<p>You can ask the people you meet about themselves or if they know anything about the ";
    text += "people who died. If you're too nosey they'll tell you to get lost though, so be judicious ";
    text += "with your questions!</p>";

    $("div#storyText").html(text);
    $("span#pageNum").html("3");
}

function page4() {
    var text = ""; 
    text += "If you ever forget the things that you've learned, you can access your naturally "; 
    text += "photographic memory with the \"Information\" button on the home screen.";

    text += "<p>Once you've gathered enough evidence to guess the killer, click the \"Guess Killer\" ";
    text += "button and take your guess. Be careful though, because you can only guess once. If you're ";
    text += "wrong, you convict the wrong person and lose the game (and the justice system).";

    $("div#storyText").html(text);
    $("span#pageNum").html("4");
    // why does this trigger a click?
    //    $("a#nextbutton").text("Start Game");
}

function nextPage() {
    if (currPage == 4) {
        $.mobile.changePage("index.php?action=new");
    } else {
        currPage++;
        var pageFunction = "page"+currPage;
        window[pageFunction]();
    }
}

function prevPage() {
    currPage--;
    var pageFunction = "page"+currPage;
    window[pageFunction]();
}

var currPage=1;
$('#story').live( 'pageinit',function(event){
    page1();
    $("#story").live("swipeleft", function(){
        nextPage();
    });
    
    $("#story").live("swiperight", function(){
        prevPage();
    });
    
    $("a#nextbutton").click(function() {
       nextPage();
    });
});

